#include <QtGui>
#include <QSharedMemory>
#include "helper.h"
#include "khelpermainwindow.h"


int main(int argc, char **argv)
{
	static const char *wpshelper_name[] = {
		QT_TRANSLATE_NOOP("wpshelper_name", "WPS Helper"),
		0
	};

	QApplication app(argc, argv);

	QTranslator translator;
	qDebug() << QLocale::system().name();
	translator.load("wpshelper_" + QLocale::system().name() + ".qm", qApp->applicationDirPath() + "/../src");
	//translator.load("wpshelper_zh_CN.qm", qApp->applicationDirPath());
	qDebug() << "path: " << qApp->applicationDirPath();

	app.installTranslator(&translator);

	app.setApplicationName(qApp->translate("wpshelper_name", wpshelper_name[0]));
	app.setOrganizationName("KSO");
	app.setQuitOnLastWindowClosed(false);

	QSharedMemory *shareMem = new QSharedMemory(QString("WPS Helper"));
	volatile short i = 2;

	while (i--)
	{
		if (shareMem->attach(QSharedMemory::ReadOnly))
		{
			shareMem->detach();
		}
	}


	if (shareMem->create(1))
	{
		KHelperMainWindow mainWindow ;

		mainWindow.setWindowFlags(Qt::FramelessWindowHint);		
		mainWindow.show();

		// KHelper *helper = new KHelper();
		// helper->hide();
		// helper->move(QApplication::desktop()->width() - helper->width(), (QApplication::desktop()->height() - helper->height()) * 0.7);
		app.exec();

		if (shareMem->isAttached())
			shareMem->detach();

		delete shareMem;
	}

	return 0;
}
